<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['base_path']?>public/css/style.css" media="screen" />
        <link rel="shortcut_icon" href="<?php echo $GLOBALS['base_path']?>public/img/icon.ico" />
		<link rel="icon" href="<?php echo $GLOBALS['base_path']?>public/img/icon.png" />
		<title>Foto</title>
        <script type="text/javascript" src="<?php echo $GLOBALS['base_path']?>public/js/fquery.js"></script>
        <script type="text/javascript" >
            function addChatLog(fullname , content) {
                var element = document.createElement('div');
                element.setAttribute('class' , 'chat');
                //element.setAttribute('id' , "");
                element.innerHTML = "<b>" + fullname + "</b> : " + content;
                document.getElementById("chatlog").appendChild(element);
            }

            function init() {
                form = document.forms["chat"];

                form.onsubmit = function() {
                    //alert(document.forms["chat"].getAttribute('action'));
                    var url = document.forms["chat"].getAttribute('action');
                    addChatLog("<?php echo $this->auth->fullname;?>" , form["content"].value);
                    ajaxPost(url, "content=" + form["content"].value, function(result) {
                        
                    });

                    form["content"].value = "";

                    return false;
                }

                everyTime(3000 , function() {
                    ajaxGet("<?php echo $this->createUrl('chat/getUnreadChat');?>" , function(result) {
                        var chats = eval(result);

                        for(var i in chats) {
                            addChatLog(chats[i]['fullname'] , chats[i]['content']);
                        }
                    });
                });
            }
        </script>
    </head>
    <body onload="init()">
        <div id="bodyWrapper">
            <?php $this->render('accountbar');?>
            <div class="dummy"></div>
            <?php $this->render('menubar');?>

            <div id="content">
                <h2>Obrolan dengan <?php echo $recipient->fullname;?></h2>
                
                <div id="chatlog" style="margin-bottom: 10px;">
                    
                </div>
                <div>
                    <form id="chat" method="post" action="<?php echo $this->createUrl('chat/send/' . $recipient->id);?>">
                        <input type="text" style="width: 400px;" name="content" />
                    </form>
                </div>
            </div>
        </div>
    </body>

</html>